//
//  HNSH_MineViewOtherCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/27.
//

#import "HNSH_MineViewOtherCell.h"

@interface HNSH_MineViewOtherCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

@end

@implementation HNSH_MineViewOtherCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)setFwAry:(NSArray *)fwAry {
    __weak __typeof(&*self)weakSelf = self;
    for (int i = 0; i < fwAry.count; i ++) {
        NSDictionary *dict = fwAry[i];
        UIView *view = [self configCellWithFrame:CGRectMake(0, 5+40*i, kScreenWidth-24, 40) icon:dict[@"image"] title:dict[@"title"]];
        [self.bgView addSubview:view];
        view.tag = i;
        view.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            if (weakSelf.otherBlock) {
                weakSelf.otherBlock(dict);
            }
        }];
        [view addGestureRecognizer:tap];
    }
}

- (void)configUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.bottom.mas_equalTo(0);
    }];
}

- (UIView *)configCellWithFrame:(CGRect)frame icon:(NSString *)icon title:(NSString *)title {
    UIView *view = [[UIView alloc]initWithFrame:frame];
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(16, 10, 20, 20)];
    imgV.image = [UIImage imageNamed:icon];
    [view addSubview:imgV];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(46, 10, 100, 20)];
    label.text = title;
    label.textColor = [UIColor appBlackLabelColor];
    label.font = [UIFont systemFontOfSize:14];
    [view addSubview:label];
    
    UIImageView *showIcon = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth-24-32, 12, 16, 16)];
    showIcon.image = [UIImage imageNamed:@"mine_bottom_cell_show_icon"];
    [view addSubview:showIcon];
    
    return view;
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8.0f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}


@end
